using System.Collections.Generic;
using SqlSugar;
using WinformTemplete.Models;

namespace WinformTemplete.Repositories
{
    public class UserRepository
    {
        private readonly SqlSugarClient _db;

        public UserRepository(SqlSugarClient db)
        {
            _db = db;
        }

        public List<User> GetAll()
        {
            return _db.Queryable<User>().ToList();
        }

        public User GetById(int id)
        {
            return _db.Queryable<User>().InSingle(id);
        }

        public bool Add(User user)
        {
            return _db.Insertable(user).ExecuteCommand() > 0;
        }

        public bool Update(User user)
        {
            return _db.Updateable(user).ExecuteCommand() > 0;
        }

        public bool Delete(int id)
        {
            return _db.Deleteable<User>().In(id).ExecuteCommand() > 0;
        }
    }
} 